package com.meaningful.thinking.thread_pool_demo;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

public class Main {

    public static void main(String[] args) {
        MyThreadPool myThreadPool = new MyThreadPool(
                2,
                3,
                1,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1),
                new DiscardRejectHandle()
        );

        for (int i = 0; i < 5; i++) {
            final int num = i;
            myThreadPool.execute(() -> {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + "_" + "任务" + num);
            });
        }

        System.out.println("主线程没有被阻塞");
    }

}
